<?php

namespace JLPay\Models\Trans\B2c;

use JLPay\Models\BaseRequest;
use JLPay\Models\Trans\Dto\TerminalInfoDto;

/**
 * 微支付预授权请求
 */
class MicroPayPreAuthRequest extends BaseRequest
{
    public const API_URL = "/open/trans/micropaypreauth";
    
    protected string $mchId = "";  // 商户号
    protected string $termNo = "";  // 终端号
    protected string $payType = "";  // 交易类型
    protected string $outTradeNo = "";  // 外部订单号
    protected string $paymentValidTime = "";  // 订单有效期
    protected string $guaranteeExpiry = "";  // 预授权交易有效期
    protected string $body = "";  // 商品标题
    protected string $attach = "";  // 商品描述
    protected string $totalFee = "";  // 交易金额
    protected string $authCode = "";  // 用户付款码
    protected string $remark = "";  // 备注
    protected string $opUserId = "";  // 操作员
    protected string $opShopId = "";  // 门店号
    protected string $deviceInfo = "";  // 终端设备号
    protected string $mchCreateIp = "";  // 终端IP
    protected string $transAddress = "";  // 交易地址
    protected string $areaCode = "";  // 交易地区码
    protected string $longitude = "";  // 经度
    protected string $latitude = "";  // 纬度
    protected bool $syncAble = false;  // 是否同步
    protected string $subAppid = "";  // 公众账号ID
    protected ?TerminalInfoDto $terminalInfo = null;  // 终端信息

    /**
     * 构造函数
     */
    public function __construct()
    {
        // 不需要调用父类构造函数
    }

    // 基础信息 getter/setter
    public function setMchId(string $mchId): self { $this->mchId = $mchId; return $this; }
    public function getMchId(): string { return $this->mchId; }
    
    public function setTermNo(string $termNo): self { $this->termNo = $termNo; return $this; }
    public function getTermNo(): string { return $this->termNo; }
    
    public function setPayType(string $payType): self { $this->payType = $payType; return $this; }
    public function getPayType(): string { return $this->payType; }
    
    public function setOutTradeNo(string $outTradeNo): self { $this->outTradeNo = $outTradeNo; return $this; }
    public function getOutTradeNo(): string { return $this->outTradeNo; }
    
    public function setPaymentValidTime(string $paymentValidTime): self { $this->paymentValidTime = $paymentValidTime; return $this; }
    public function getPaymentValidTime(): string { return $this->paymentValidTime; }
    
    public function setGuaranteeExpiry(string $guaranteeExpiry): self { $this->guaranteeExpiry = $guaranteeExpiry; return $this; }
    public function getGuaranteeExpiry(): string { return $this->guaranteeExpiry; }
    
    public function setBody(string $body): self { $this->body = $body; return $this; }
    public function getBody(): string { return $this->body; }
    
    public function setAttach(string $attach): self { $this->attach = $attach; return $this; }
    public function getAttach(): string { return $this->attach; }
    
    public function setTotalFee(string $totalFee): self { $this->totalFee = $totalFee; return $this; }
    public function getTotalFee(): string { return $this->totalFee; }
    
    public function setAuthCode(string $authCode): self { $this->authCode = $authCode; return $this; }
    public function getAuthCode(): string { return $this->authCode; }
    
    public function setRemark(string $remark): self { $this->remark = $remark; return $this; }
    public function getRemark(): string { return $this->remark; }
    
    public function setOpUserId(string $opUserId): self { $this->opUserId = $opUserId; return $this; }
    public function getOpUserId(): string { return $this->opUserId; }
    
    public function setOpShopId(string $opShopId): self { $this->opShopId = $opShopId; return $this; }
    public function getOpShopId(): string { return $this->opShopId; }
    
    public function setDeviceInfo(string $deviceInfo): self { $this->deviceInfo = $deviceInfo; return $this; }
    public function getDeviceInfo(): string { return $this->deviceInfo; }
    
    public function setMchCreateIp(string $mchCreateIp): self { $this->mchCreateIp = $mchCreateIp; return $this; }
    public function getMchCreateIp(): string { return $this->mchCreateIp; }
    
    public function setTransAddress(string $transAddress): self { $this->transAddress = $transAddress; return $this; }
    public function getTransAddress(): string { return $this->transAddress; }
    
    public function setAreaCode(string $areaCode): self { $this->areaCode = $areaCode; return $this; }
    public function getAreaCode(): string { return $this->areaCode; }
    
    public function setLongitude(string $longitude): self { $this->longitude = $longitude; return $this; }
    public function getLongitude(): string { return $this->longitude; }
    
    public function setLatitude(string $latitude): self { $this->latitude = $latitude; return $this; }
    public function getLatitude(): string { return $this->latitude; }
    
    public function setSyncAble(bool $syncAble): self { $this->syncAble = $syncAble; return $this; }
    public function getSyncAble(): bool { return $this->syncAble; }
    
    public function setSubAppid(string $subAppid): self { $this->subAppid = $subAppid; return $this; }
    public function getSubAppid(): string { return $this->subAppid; }
    
    public function setTerminalInfo(?TerminalInfoDto $terminalInfo): self { $this->terminalInfo = $terminalInfo; return $this; }
    public function getTerminalInfo(): ?TerminalInfoDto { return $this->terminalInfo; }

    /**
     * 转换为数组
     *
     * @return array
     */
    public function toArray(): array
    {
        $data = parent::toArray();
        
        // 基础信息
        if ($this->mchId) $data['mch_id'] = $this->mchId;
        if ($this->termNo) $data['term_no'] = $this->termNo;
        if ($this->payType) $data['pay_type'] = $this->payType;
        if ($this->outTradeNo) $data['out_trade_no'] = $this->outTradeNo;
        if ($this->paymentValidTime) $data['payment_valid_time'] = $this->paymentValidTime;
        if ($this->guaranteeExpiry) $data['guarantee_expiry'] = $this->guaranteeExpiry;
        if ($this->body) $data['body'] = $this->body;
        if ($this->attach) $data['attach'] = $this->attach;
        if ($this->totalFee) $data['total_fee'] = $this->totalFee;
        if ($this->authCode) $data['auth_code'] = $this->authCode;
        if ($this->remark) $data['remark'] = $this->remark;
        if ($this->opUserId) $data['op_user_id'] = $this->opUserId;
        if ($this->opShopId) $data['op_shop_id'] = $this->opShopId;
        if ($this->deviceInfo) $data['device_info'] = $this->deviceInfo;
        if ($this->mchCreateIp) $data['mch_create_ip'] = $this->mchCreateIp;
        if ($this->transAddress) $data['trans_address'] = $this->transAddress;
        if ($this->areaCode) $data['area_code'] = $this->areaCode;
        if ($this->longitude) $data['longitude'] = $this->longitude;
        if ($this->latitude) $data['latitude'] = $this->latitude;
        $data['sync_able'] = $this->syncAble;
        if ($this->subAppid) $data['sub_appid'] = $this->subAppid;
        
        // 复杂对象
        if ($this->terminalInfo) $data['terminal_info'] = $this->terminalInfo->toArray();
        
        return $data;
    }
} 